<!DOCTYPE html>
<html>
<head>
    <script>if (window !== top) top.location.replace(location.href);</script>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="${ctxPath}/assets/expand/images/favicon.ico" rel="icon">
    <title>登录 - Guns</title>
    <link rel="stylesheet" href="${ctxPath}/assets/common/libs/layui/css/layui.css?v=${constants.getReleaseVersion()}"/>
    <link rel="stylesheet" href="${ctxPath}/assets/common/module/admin.css?v=${constants.getReleaseVersion()}"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            background-image:linear-gradient(135deg, #168af0 0%, #6eeaa4 100%);
            background-repeat: no-repeat;
            background-size: cover;
            min-height: 100vh;
        }

        body:before {
            content: "";
            background-color: rgba(0, 0, 0, .2);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }

        .login-wrapper {
            max-width: 420px;
            padding: 20px;
            margin: 0 auto;
            position: relative;
            box-sizing: border-box;
            z-index: 2;
        }

        .login-wrapper > .layui-form {
            padding: 25px 30px;
            background-color: #fff;
            box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.19);
            box-sizing: border-box;
            border-radius: 4px;
        }

        .login-wrapper > .layui-form > h2 {
            color: #333;
            font-size: 18px;
            text-align: center;
            margin-bottom: 25px;
        }

        .login-wrapper > .layui-form > .layui-form-item {
            margin-bottom: 25px;
            position: relative;
        }

        .login-wrapper > .layui-form > .layui-form-item:last-child {
            margin-bottom: 0;
        }

        .login-wrapper > .layui-form > .layui-form-item > .layui-input {
            height: 46px;
            line-height: 46px;
            border-radius: 2px !important;
        }

        .login-wrapper .layui-input-icon-group > .layui-input {
            padding-left: 46px;
        }

        .login-wrapper .layui-input-icon-group > .layui-icon {
            width: 46px;
            height: 46px;
            line-height: 46px;
            font-size: 20px;
            color: #909399;
            position: absolute;
            left: 0;
            top: 0;
            text-align: center;
        }

        .login-wrapper > .layui-form > .layui-form-item.login-captcha-group {
            padding-right: 135px;
        }

        .login-wrapper > .layui-form > .layui-form-item.login-captcha-group > .login-captcha {
            height: 46px;
            width: 120px;
            cursor: pointer;
            box-sizing: border-box;
            border: 1px solid #e6e6e6;
            border-radius: 2px !important;
            position: absolute;
            right: 0;
            top: 0;
        }

        .login-wrapper > .layui-form > .layui-form-item > .layui-form-checkbox {
            margin: 0 !important;
            padding-left: 25px;
        }

        .login-wrapper > .layui-form > .layui-form-item > .layui-form-checkbox > .layui-icon {
            width: 15px !important;
            height: 15px !important;
        }

        .login-wrapper > .layui-form .layui-btn-fluid {
            height: 48px;
            line-height: 48px;
            font-size: 16px;
            border-radius: 2px !important;
        }

        .login-wrapper > .layui-form > .layui-form-item.login-oauth-group > a > .layui-icon {
            font-size: 26px;
        }

        .login-copyright {
            color: #eee;
            padding-bottom: 20px;
            text-align: center;
            position: relative;
            z-index: 1;
        }

        \@media screen and (min-height: 550px) {
            .login-wrapper {
                margin: -250px auto 0;
                position: absolute;
                top: 50%;
                left: 0;
                right: 0;
                width: 100%;
            }

            .login-copyright {
                position: absolute;
                bottom: 0;
                right: 0;
                left: 0;
            }
        }

        .layui-btn {
            background-color: #5FB878;
            border-color: #5FB878;
        }

        .layui-link {
            color: #5FB878 !important;
        }

        canvas {
            display: inline-block;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<canvas id="canvas" width="1920" height="1080"></canvas>
<div class="login-wrapper layui-anim layui-anim-scale layui-hide">
        <form class="layui-form">
        <h2>用户登录</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" id="account" name="account" placeholder="请输入登录账号" autocomplete="off" lay-verType="tips" lay-verify="required" required/>
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input class="layui-input" id="password" name="password" placeholder="请输入登录密码" type="password" lay-verType="tips" lay-verify="required" required/>
        </div>
        @if(security.getCaptchaOpen()){
        <div class="layui-form-item layui-input-icon-group login-captcha-group">
            <i class="layui-icon layui-icon-auz"></i>
            <input id="verKey" name="verKey" type="hidden"/>
            <input class="layui-input" id="verCode" name="verCode" placeholder="请输入验证码" autocomplete="off" lay-verType="tips" maxlength="5" lay-verify="required" required/>
            <img class="login-captcha" alt=""/>
        </div>

        @}
        <div class="layui-form-item">
            <input type="checkbox" id="rememberMe" name="rememberMe" title="记住密码" lay-skin="primary" checked>
            <a href="${ctxPath}/register" class="layui-link pull-right">注册账号</a>
        </div>
        <div class="layui-form-item">
            <button id="loginSubmit" class="layui-btn layui-btn-fluid" lay-filter="loginSubmit" lay-submit>登录</button>
        </div>
        <div class="layui-form-item login-oauth-group text-center">
            <a href="${ctxPath}/oauth/render/qq"><i class="layui-icon layui-icon-login-qq" style="color:#3492ed;"></i></a>&emsp;
            <a href="${ctxPath}/oauth/render/gitee">
                <img class="layui-icon" style="height: 28px;width: 28px; margin-top: -12px !important;" src="${ctxPath}/assets/expand/images/git.png"/>
            </a>
        </div>
        </form>

</div>
<div class="login-copyright">copyright © 2020 stylefeng.cn all rights reserved.</div>

@/* 加入contextPath属性和session超时的配置 */
<script type="text/javascript">
    var Feng = {
        ctxPath: "${ctxPath}",
        version: '${constants.getReleaseVersion()}'
    };
</script>

<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/common/libs/layui/layui.js?v=${constants.getReleaseVersion()}"></script>
<script type="text/javascript" src="${ctxPath}/assets/common/js/common.js?v=${constants.getReleaseVersion()}"></script>
<script>
    layui.use(['layer', 'form', 'index', 'HttpRequest','admin','notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var HttpRequest = layui.HttpRequest;
        var index = layui.index;
        var admin = layui.admin;
        var notice = layui.notice;

        $('.login-wrapper').removeClass('layui-hide');

        var errorMsg = "${tips!}";
        if (errorMsg) {
            layer.msg(errorMsg, {icon: 5, anim: 6});
        }

        // 获取验证码
        function getKaptcha(){
            var request = new HttpRequest(Feng.ctxPath + '/captcha'+ '?t=' + (new Date).getTime(), 'get');
            var result = request.start();
            $("#verKey").val(result.data.verKey)
            $('img.login-captcha').attr('src', result.data.verImage);
        }

        // 点击刷新验证码
        $('img.login-captcha').click(function () {
            getKaptcha();
        });

        // 开启验证码
        @if(security.getCaptchaOpen()){
            getKaptcha();
        @}

        // 登录操作
        form.on('submit(loginSubmit)', function (data){
            admin.btnLoading('#loginSubmit',"登录中");
            var request = new HttpRequest(Feng.ctxPath + "/login", 'post', function (data) {
                // 清除顶部选择应用的缓存
                index.clearTabCache();
                // 重定向到首页
                window.location.href = Feng.ctxPath + "/";
            }, function (data) {
                @if(security.getCaptchaOpen()){
                    //清空输入框
                    $("#verCode").val('');
                    //刷新验证码
                    getKaptcha();
                @}
                //停止loading
                admin.btnLoading('#loginSubmit', false);
                notice.msg(data.message, {icon: 2});
            });
            data.field.rememberMe=$("#rememberMe").prop("checked");
            request.set(data.field);
            request.start(true);
            return false;
        });

        // canvas绘画
        window.requestAnimationFrame =
        window.requestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.msRequestAnimationFrame;

        var canvas = document.getElementById("canvas");
        var ctx = canvas.getContext("2d");
        var w = canvas.width = canvas.offsetWidth;
        var h = canvas.height = canvas.offsetHeight;
        var circles = [];

        init(180);

        function init(num) {
            for (var i = 0; i < num; i++) {
                newobject(Math.random() * w, Math.random() * h);
            }
            draw();
        }

        function newobject(x, y) {
            var object = new Object();
            object.x = x;
            object.y = y;
            object.r = Math.random() * 3;
            object._mx = Math.random();
            object._my = Math.random();
            circles.push(object);
        }

        function drawCircle(obj) {
            ctx.beginPath();
            ctx.arc(obj.x, obj.y, obj.r, 0, 360);
            ctx.closePath();
            ctx.fillStyle = "rgba(204, 204, 204, 0.3)";
            ctx.fill();
        }

        function drawLine(obj1, obj) {
            let dx = obj1.x - obj.x;
            let dy = obj1.y - obj.y;
            let d = Math.sqrt(dx * dx + dy * dy);
            if (d < 60) {
                ctx.beginPath();
                ctx.lineWidth = 0.5;
                ctx.moveTo(obj1.x, obj1.y); //start
                ctx.lineTo(obj.x, obj.y); //end
                ctx.closePath();
                ctx.strokeStyle = "rgba(204, 204, 204, 0.3)";
                ctx.stroke();
            }
        }

        function move(obj) {
            obj._mx = obj.x < w && obj.x > 0 ? obj._mx : -obj._mx;
            obj._my = obj.y < h && obj.y > 0 ? obj._my : -obj._my;
            obj.x += obj._mx / 2;
            obj.y += obj._my / 2;
        }

        function draw() {
            ctx.clearRect(0, 0, w, h);
            for (let i = 0; i < circles.length; i++) {
                move.call(circles[i], circles[i]);
                drawCircle.call(circles[i], circles[i]);
                for (let j = i + 1; j < circles.length; j++) {
                    drawLine.call(circles[i], circles[i], circles[j]);
                }
            }
            requestAnimationFrame(draw);
        }

    });
</script>

</body>
</html>
